package com.todo.delicacy.application.frontend.service.impl;

import com.todo.common.common.entity.response.BizResponse;
import com.todo.common.common.enums.BizErrorCodeEnum;
import com.todo.common.common.exception.BizException;
import com.todo.delicacy.application.convert.FoodConvert;
import com.todo.delicacy.application.entity.bo.FoodInfoBO;
import com.todo.delicacy.application.frontend.service.FoodInfoAggService;
import com.todo.delicacy.application.service.FoodInfoService;
import com.todo.delicacy.iface.frontend.request.QueryFoodDetailParam;
import com.todo.delicacy.iface.frontend.request.QueryFoodListByNameParam;
import com.todo.delicacy.iface.frontend.request.QueryFoodListByRestaurantParam;
import com.todo.delicacy.iface.frontend.response.FoodBaseVO;
import com.todo.delicacy.iface.frontend.response.FoodDetailVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (FoodInfo)表服务实现类
 *
 * @author zhangwenxiang
 * @since 2024-03-04 00:19:46
 */
@Slf4j
@Service("foodInfoAggService")
public class FoodInfoAggServiceImpl implements FoodInfoAggService {

    @Resource
    private FoodInfoService foodInfoService;

    @Override
    public BizResponse<List<FoodBaseVO>> queryFoodListByRestaurantId(QueryFoodListByRestaurantParam param) {
        if (param == null || !param.baseCheck()) {
            throw new BizException(BizErrorCodeEnum.PARAM_ERROR);
        }
        List<FoodInfoBO> foodInfoBOList = foodInfoService.queryFoodInfoListByRestaurantId(param.getRestaurantId());
        return BizResponse.success(FoodConvert.convertToFoodBaseVOList(foodInfoBOList));
    }

    @Override
    public BizResponse<List<FoodBaseVO>> queryFoodListByName(QueryFoodListByNameParam param) {
        if (param == null || !param.baseCheck()) {
            throw new BizException(BizErrorCodeEnum.PARAM_ERROR);
        }
        List<FoodInfoBO> foodInfoBOList = foodInfoService.queryFoodInfoListByName(param.getName(), param.getRestaurantId());
        return BizResponse.success(FoodConvert.convertToFoodBaseVOList(foodInfoBOList));
    }

    @Override
    public BizResponse<FoodDetailVO> queryFoodDetailById(QueryFoodDetailParam param) {
        if (param == null || !param.baseCheck()) {
            throw new BizException(BizErrorCodeEnum.PARAM_ERROR);
        }
        FoodInfoBO foodInfoBO = foodInfoService.queryFoodInfoById(param.getFoodId());
        return BizResponse.success(FoodConvert.convertToFoodDetailVO(foodInfoBO));
    }
}
